package com.heny.demo.common;

import com.heny.demo.service.BaseDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author litao.cc
 * @version BaseDataServiceBean.java v0.1 t2025/5/6 22:23
 * @date 2025/5/6 22:23
 * @description BaseDataServicebean
 */
@Service
public class BaseDataServiceBean {
    @Autowired
    @Qualifier("stationHBaseDataService")
    private BaseDataService stationHBaseDataService;

    @Autowired
    @Qualifier("stationDBaseDataService")
    private BaseDataService stationDBaseDataService;

    @Autowired
    @Qualifier("stationMBaseDataService")
    private BaseDataService stationMBaseDataService;

    @Autowired
    @Qualifier("stationYBaseDataService")
    private BaseDataService stationYBaseDataService;

    @Autowired
    @Qualifier("deviceHBaseDataService")
    private BaseDataService deviceHBaseDataService;

    @Autowired
    @Qualifier("deviceDBaseDataService")
    private BaseDataService deviceDBaseDataService;

    @Autowired
    @Qualifier("deviceMBaseDataService")
    private BaseDataService deviceMBaseDataService;

    @Autowired
    @Qualifier("deviceYBaseDataService")
    private BaseDataService deviceYBaseDataService;

    public BaseDataService getBaseDataService(String dataType,String statisticsType){
        Map<String,Map<String,BaseDataService>> map = new HashMap<String,Map<String,BaseDataService>>() {{
            put("STATION", new HashMap<String,BaseDataService>(){{
                put("HOUR",stationHBaseDataService);
                put("DAY",stationDBaseDataService);
                put("MONTH",stationMBaseDataService);
                put("YEAR",stationYBaseDataService);
            }});
            put("DEVICE",new HashMap<String,BaseDataService>(){{
                put("HOUR",deviceHBaseDataService);
                put("DAY",deviceDBaseDataService);
                put("MONTH",deviceMBaseDataService);
                put("YEAR",deviceYBaseDataService);
            }});
        }};


        if(map.containsKey(dataType)){
            Map<String, BaseDataService> dataServiceMap = map.get(dataType);
            if(dataServiceMap.containsKey(statisticsType)){
                return dataServiceMap.get(statisticsType);
            }
        }
        throw new CommonException(CommonErrorCode.PARAM_VALIDATION_FAILED,"不支持的数据获取枚举");
    }
}
